import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Form/index';
import { getDictTypeListApi } from '/@/api/admin/dict';
import { ref } from 'vue';
import { DICT } from '/@/enums/dict';

const roleTypeList = ref([]);
export async function getRoleTypeList() {
  const res: any = await getDictTypeListApi({ type: DICT.BPMN_RANGE_TYPE });
  roleTypeList.value = res || [];
}
export const roleColumns: BasicColumn[] = [
  {
    title: '角色名称',
    dataIndex: 'roleName',
  },
  {
    title: '初始值',
    dataIndex: 'initValue',
  },
  {
    title: '角色范围',
    dataIndex: 'roleRange',
  },
  {
    title: '角色类型',
    dataIndex: 'roleType',
    customRender: ({ record }) => {
      const item: any = roleTypeList.value.find((i: any) => i.value == record.roleType);
      if (item) {
        return item.label;
      } else {
        return '';
      }
    },
  },
  {
    title: '最大限制人数',
    dataIndex: 'selectUserNum',
  },
  {
    title: '最多选择次数',
    dataIndex: 'maxLimitedNum',
  },
  {
    title: '标识',
    dataIndex: 'roleId',
  },
];

export const roleSchemas: FormSchema[] = [
  {
    field: 'roleName',
    component: 'Input',
    label: `角色名称`,
    rules: [{ required: true }],
    colProps: {
      span: 12,
    },
  },
  {
    field: 'initValue',
    component: 'Input',
    label: `初始值`,
    colProps: {
      span: 12,
    },
  },
  {
    field: 'roleRange',
    component: 'Input',
    label: `角色范围`,
    colProps: {
      span: 12,
    },
  },
  {
    field: 'roleType',
    label: '角色类型',
    component: 'ApiSelect',
    colProps: {
      span: 12,
    },
    componentProps: {
      api: async () => {
        return roleTypeList.value || [];
      },
      valueField: 'intValue',
      allowClear: false,
      params: {
        type: '',
      },
    },
  },
  {
    field: 'haveSelectUserNum',
    component: 'RadioGroup',
    label: '是否有人员最大限制数',
    colProps: {
      span: 12,
    },
    componentProps: {
      options: [
        {
          label: '是',
          value: 1,
        },
        {
          label: '否',
          value: 0,
        },
      ],
    },
  },
  {
    field: 'selectUserNum',
    component: 'InputNumber',
    label: `最大限制人数`,
    colProps: {
      span: 12,
    },
  },
  {
    field: 'maxLimitedNum',
    component: 'InputNumber',
    label: `最多选择次数`,

    colProps: {
      span: 12,
    },
  },
];

export const field = {
  haveSelectUserNum: 0,
  initCacuCont: '',
  initReturnType: 1,
  initValue: '',
  maxLimitedNum: 0,
  roleId: 1,
  roleName: '',
  roleRange: '',
  roleType: 0,
  selectUserNum: 0,
  sendCacuCont: '',
  sendReturnType: 1,
  value: '',
};
